#version 120
#extension GL_EXT_geometry_shader4:require

uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;

varying in  float age_geom[1];
varying out float age_frag;
varying out vec2  uv_frag;
varying out vec4  position_frag;

vec4 billboard(vec4 p, vec2 delta)
{
    return p + vec4(delta.x, delta.y, 0.0, 0.0);
}

void main()
{
    float s		= 0.5 * gl_PointSizeIn[0];
	
    vec4 p		= gl_PositionIn[0];

	age_frag = age_geom[0];
	uv_frag		= vec2(0,0);
	position_frag = p;
    gl_Position = projectionMatrix * billboard(p, vec2(-s, -s));
    EmitVertex();

	age_frag = age_geom[0];
	uv_frag		= vec2(1,0);
	position_frag = p;
    gl_Position = projectionMatrix * billboard(p, vec2(s, -s));
    EmitVertex();

	age_frag = age_geom[0];
	uv_frag		= vec2(0,1);
    gl_Position = projectionMatrix * billboard(p, vec2(-s, s));
    EmitVertex();

	age_frag = age_geom[0];
	uv_frag		= vec2(1,1);
	position_frag = p;
    gl_Position = projectionMatrix * billboard(p, vec2(s, s));
    EmitVertex();

    EndPrimitive();
}